package cn.itcast.dao;

import cn.itcast.pojo.*;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Set;

public interface RoleDao {
    //根据条件查询检查项
    Page<Role> selectByCondition(String queryString);

    //修改数据
    @Update("update t_role set name = #{name},keyword = #{keyword},description = #{description} where id = #{id}")
    void updateRole(Role role);

    //根据name查询role
    @Select("select * from t_role where name = #{name}")
    Role selectRoleByName(String name);

    //根据id查询数据
    @Select("select * from t_role where id = #{id}")
    Role findById(Integer id);

    //根据id删除角色数据
    @Delete("delete from t_role where id = #{id}")
    void deleteById(Integer id);

    //根据id删除菜单数据
    @Delete("delete from t_role_menu where role_id = #{id}")
    void deleteMenuById(Integer id);

    //根据id删除权限数据
    @Delete("delete from t_role_permission where role_id= #{id}")
    void deletePermissionById(Integer id);


    //角色id和菜单id绑定
    @Insert("insert into t_role_menu values (#{id},#{menuid})")
    void roleIdAndMenuId(@Param("id") Integer id,@Param("menuid") Integer menuid);

    //角色id和权限id绑定
    @Insert("insert into t_role_permission values (#{id},#{permissionid})")
    void roleIdAndPermissionId(@Param("id") Integer id,@Param("permissionid") Integer permissionid);

    //根据id查询是否关联菜单
    @Select("select count(*) from t_role_menu where role_id=#{id}")
    int selectToMenu(Integer id);

    //根据id查询是否关联权限
    @Select("select count(*) from t_role_permission where role_id = #{id}")
    int selectToPermission(Integer id);


    //根据id查询关联的菜单
    @Select("select menu_id from t_role_menu where role_id = #{id}")
    Integer[] roleMenu(Integer id);

    //根据id查询关联的权限
    @Select("select permission_id from t_role_permission where role_id = #{id}")
    Integer[] rolePermission(Integer id);

    //添加角色表数据
    void addRole(Role role);

    //菜单权限查询
    Set<Permission> findMenuAssociationPermission(@Param(value = "menuId") Integer menuId);


    //查询菜单数据(调用权限层的方法)  待用
    Page<Menu> findAllMenu();
}